package com.hhkj.api.course.service.biz.impl;

import cn.hutool.core.bean.BeanUtil;
import com.hhkj.admin.course.common.cont.CourseConst;
import com.hhkj.admin.course.domain.Course;
import com.hhkj.admin.course.service.base.CourseService;
import com.hhkj.admin.course.model.dopo.CoursePriceConfPo;
import com.hhkj.admin.course.service.base.CoursePriceConfService;
import com.hhkj.api.course.model.req.ApiCoursePriceReq;
import com.hhkj.api.course.model.res.ApiCoursePriceRes;
import com.hhkj.api.course.service.biz.ApiSaleCoursePriceBizService;
import com.ruoyi.common.exception.GlobalException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ApiSaleCoursePriceBizServiceImpl
 *
 * @author zheng
 * @since 2023/11/2 21:19
 */
@Service
public class ApiSaleCoursePriceBizServiceImpl implements ApiSaleCoursePriceBizService {

    @Autowired
    private CoursePriceConfService coursePriceConfService;

    @Autowired
    private CourseService courseService;

    @Override
    public List<ApiCoursePriceRes> list(ApiCoursePriceReq req) {
        Course coursePo = courseService.getById(req.getCourseId());
        if (!CourseConst.LEVEL_NUM_THIRD.equals(coursePo.getLevelNum())) {
            throw new GlobalException("科目信息不正确");
        }
        req.setCourseId(coursePo.getParentId());
        List<CoursePriceConfPo> priceConfList = coursePriceConfService.listPoByDo(req);
        return BeanUtil.copyToList(priceConfList, ApiCoursePriceRes.class);
    }
}
